package ${package}.controllers;

import java.util.Map;
import org.apache.log4j.Logger;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trustexporter.common.utils.JsonResult;
import com.trustexporter.model.${table_name};
import com.trustexporter.query.${table_name}Query;
import com.trustexporter.service.I${table_name}Service;

@Controller
@RequestMapping(value = "/${table_name?uncap_first}")
public class ${table_name}Controller extends  BaseController {

	private Logger log = Logger.getLogger(this.getClass());

	@Autowired
	private I${table_name}Service ${table_name?uncap_first}Service;
	
	
	/**
	 * 说明：分页
	 * @param request
	 * @param response
	 * @return
	 */
	 @SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping(value="/pagelist" )
	 @ResponseBody
	public JsonResult<Map<String, Object>> pageList(ModelMap model,${table_name}Query query){
		 Map<String , Object> map = ${table_name?uncap_first}Service.find${table_name}PageList(query);
		jsonResult = new JsonResult<Map<String, Object>>(true, "", 1, "", map);
		return jsonResult;
	}
	
	@RequestMapping(value="/get" )
	public @ResponseBody JsonResult<${table_name}> get(Long ${table_name?uncap_first}Id){
		jsonResult = new JsonResult<${table_name}>(true, "", 1, "", this.${table_name?uncap_first}Service.find${table_name}ById(${table_name?uncap_first}Id));
		return jsonResult;
		}
		
	/**
	 * 说明：新增
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public @ResponseBody JsonResult<Integer> add(Model model,${table_name} ${table_name?uncap_first},HttpServletRequest request){
		int result = this.${table_name?uncap_first}Service.add${table_name}(${table_name?uncap_first});
		jsonResult = new JsonResult<Integer>(true, "", 1, "", 1);
		return jsonResult;
	}
	
	/**
	 * 说明：删除前台评论用户表信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/del" )
	public @ResponseBody JsonResult<Integer> del(Long userId){
		this.${table_name?uncap_first}Service.remove${table_name}ById(userId);
		jsonResult = new JsonResult<Integer>(true, "", 1, "", 1);
		return jsonResult;
	}
	
	/**
	 * 说明：编辑前台评论用户表信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/edit" )
	public @ResponseBody JsonResult<Integer> edit(${table_name} ${table_name?uncap_first}){
		String  result = this.${table_name?uncap_first}Service.modify${table_name}ById(${table_name?uncap_first});
		jsonResult = new JsonResult<Integer>(true, "", 1, "", 1);
		return jsonResult;
	}
	
}